# 大类：经营状况
# 小类：产品信息

import time


# 27-产品信息-2018-05-26
def get_product(mongo_instance, soup, cid, company):
    print('start 产品信息数据*******')
    if soup.find('div', id='_container_product'):
        for tr in soup.find('div', id='_container_product').find('tbody').find_all('tr'):
            item = {}
            tds = tr.find_all('td')
            if tds:
                try:
                    item['ico'] = tds[1].find('img')['src']
                except:
                    print(cid, 'get_product====================================')
                    item['ico'] = ''
                if len(tds) > 5:
                    if tds[1].find('tbody'):
                        item['product_name'] = tds[1].find('tbody').find_all('td')[1].text
                        item['simple_name'] = tds[4].text
                        item['type'] = tds[5].text  # 产品分类
                        item['type2'] = tds[6].text  # 领域
                        item['detail_url'] = tds[7].find('a')['href']
                        item['company'] = company
                        item['company_id'] = cid
                        item['create_at'] = int(time.time())
                        item['update_at'] = item['create_at']
                        print(item)
                        mongo_instance.product.update({'company_id': cid}, item, True)

    print('success 产品信息数据*******')
